<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	  layout:decorator="layout">
<head>
<style type="text/css">
div label{
	line-height:30px;
	vertical-align:top;
}
div .inline-box{
	line-height:30px;
}

</style>
<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
function to_return(){
	$("#form3").submit();
}

function to_logout(){
	$.ajax({
        url: '/user/logout',
        type: 'POST',
        crossDomain: true,
        dataType: 'json',
        contentType: 'application/json',
        data: JSON.stringify({
     	   'uid': sessionStorage.getItem('uid'),
           'token': sessionStorage.getItem('token')
        }),
        success: function (r) {
          if (r.header.code === '200' || r.header.code === '202') {
         	 sessionStorage.clear();
             localStorage.clear();
                     
            
            window.parent.location.href="../login.html";
          } 
        }
 	})	
}

function to_openUpload(){
	$("#file").val("");
	$("#myModal1").modal('show');
}

function to_upload(){
	var tmpval = $("#file").val();	
	if("" == tmpval){
		alert("请选择需要上传的文件!")
	}
	else{
		var formData = new FormData($("#form2")[0]);
		
		$.ajax({  
			url: "/uploadPackageExcel", 
			type: "post",
			data: formData,
			dataType: "json",
			async: false,  
	        cache: false,  
	        contentType: false,  
	        processData: false, 
			success: function(datas){
				if(datas.header.code == '200'){
					$("#myModal1").modal('hide');
					alert(datas.header.message);
					to_return();
				}
	     	},
			error: function (jqXHR, textStatus, errorThrown) {
				alert(errorThrown);
			}
		});
	}	
}

/*]]>*/
</script>
</head>
<body>
	<section layout:fragment="chcontent">
		<div>
			<div class="clearfix"></div>
			<div class="row">
				<div class="col-md-12">
					<div class="x_panel">
						<div class="x_title">
							资源打包操作
							<div class="pull-right" style="margin-top: -5px;">
								<a onclick="to_return()">
									<div style="width:50%;display:inline;">
										<i class="fa fa-angle-left"></i> &nbsp;返回&nbsp;&nbsp;
									</div>
								</a>
								<a onclick="to_logout()">
									<div style="width:50%;display:inline;">
										<i class="fa fa-angle-left"></i> &nbsp;退出&nbsp;&nbsp;
									</div>
								</a>
							</div>
						</div>
						<div class="x_content">
							<form class="form-inline" style="height:0px;" id="form3" th:action="@{/main}" th:method="post"></form>
							<form class="form-horizontal" id="form1">
								<table>
									<tr>
										<td width="10%">需打包资源：</td>
										<td>
											<div>
												<button type="button" class="btn btn-private1" onclick="to_openUpload()">导入</button>
											</div>
										</td>
										<td width="20%"><span style="color:red;">(注意:上传xls、xlsx文件)</span></td>
										<td width="35%"></td>
									</tr>
								</table>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-header">
		                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		                <h4 class="modal-title" id="myModalLabel">导入文件</h4>
		            </div>
		            <div class="modal-body">
		            	<form class="form-horizontal" id="form2">
		            		<div class="form-group">
							    <label for="" class="form-lab control-label edit_lab">选择文件:</label>
							    <div class="form-div edit_div1">
							    	<input type="file" class="form-control" name="file" id="file" onchange="var checkflag = checkExcelType(this); if(!checkflag){this.value = ''};"/>
							    </div>
		            		</div>
		            	</form>
		            </div>
		            <div class="modal-footer" style="text-align:center;">
		            	<button type="button" class="btn btn-private1" onclick="to_upload()"><i class="fa fa-save"></i>&nbsp;&nbsp;确定</button>
	                	<button type="button" class="btn btn-private2" data-dismiss="modal"><i class="fa fa-hand-o-down"></i>&nbsp;&nbsp;取消</button>	
		            </div>
		        </div>
		    </div>
		</div>
	</section>
</body>
</html>